
package #1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import #2
import #3
import #4
import #5

@Service
@Transactional
public class #6 implements #7 {

    @Autowired
    private #8 #9;

    @Override
    public ResultBean<#a> save(#a p){
        #a newP = #9.save(p);
        if (newP == null)
            return ResultBean.createFail("添加失败");
        return ResultBean.createSuccess("添加成功", newP);
    }
    
    @Override
    public ResultBean<String> delete(String id){
        if (!#9.existsById(id))
            return ResultBean.createFail("id不存在无法删除");
        #9.deleteById(id);
        return ResultBean.createSuccess("删除成功");
    }
    
    @Override
    public ResultBean<#a> update(#a p){
        if (!#9.existsById(p.getId()))
            return ResultBean.createFail("id不存在无法更新");
        #a newP = #9.save(p);
        return ResultBean.createSuccess("更新成功", newP);
    }
    
    @Override
    public PageBean<#a> getList(int pageIndex,int pageSize){
        long total = #9.count();
        PageBean<#a> pageBean = PageBean.newInstance();
        Sort sort = CommonUtil.getDescSort("createTime");
        Pageable pageable = CommonUtil.getPageRequest(pageIndex, pageSize, total, sort, pageBean);
        Page<#a> page = #9.findAll(pageable);
        pageBean.setPageInfos(page.getContent());
        return pageBean;
    }

}
